package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Travel;
import cn.wolfcode.trip.base.domain.TravelAllSee;
import cn.wolfcode.trip.base.domain.TravelContent;
import cn.wolfcode.trip.base.mapper.TravelAllSeeMapper;
import cn.wolfcode.trip.base.mapper.TravelCommendMapper;
import cn.wolfcode.trip.base.mapper.TravelContentMapper;
import cn.wolfcode.trip.base.mapper.TravelMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.ITravelAllSeeService;
import cn.wolfcode.trip.base.service.ITravelService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class TravelAllSeeServiceImpl implements ITravelAllSeeService {
    @Autowired
    private TravelAllSeeMapper travelAllSeeMapper;


    @Override
    public PageInfo<TravelAllSee> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize(), qo.getOrderBy());
        List<TravelAllSee> list = travelAllSeeMapper.selectForList(qo);
        return new PageInfo<>(list);
    }

    @Override
    public void saveOrUpdate(TravelAllSee entity) {
        if (entity.getId() != null){
            travelAllSeeMapper.updateByPrimaryKey(entity);
        }else {
            TravelAllSee travelAllSee = travelAllSeeMapper.selectByTravelId(entity.getTravel().getId());
            if (travelAllSee != null){
                throw new RuntimeException("已经设置为大家都在看了!");
            }
            travelAllSeeMapper.insert(entity);
        }
    }
}
